package com.scienview.permission.user.controller;


import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.scienview.core.Constants;
import com.scienview.core.anotation.Access;
import com.scienview.core.context.ContextHolder;
import com.scienview.core.enums.Level;
import com.scienview.permission.user.model.User;
import com.scienview.permission.user.model.User.Sex;
import com.scienview.platform.controller.BaseController;
import com.scienview.platform.exception.BaseException;
import com.scienview.platform.json.Json;

@Controller
@RequestMapping("/permission/user")
public class UserController extends BaseController{

	@RequestMapping("/login")
	@Access(level=Level.GUEST,task="用户登录",code="user.login")
	public ModelAndView login()throws BaseException{
		ContextHolder.getContext().getRequest().getSession().setAttribute(Constants.SESSION_USER,"王建栋");
		MyTest t=new MyTest();
		System.out.println("login");
		return null;
	}
	
	
	@RequestMapping("/logout")
	@Access(level=Level.GUEST,task="用户退出",code="user.out")
	public ModelAndView logout()throws BaseException{
		System.out.println("..........");
		ContextHolder.getContext().getRequest().getSession().invalidate();
		return null;
	}
	
	
	@RequestMapping("/addUser")
	@Access(level=Level.PERMISSION,task="新增用户",code="user.addUser")
	public ModelAndView addUser()throws BaseException{
		System.out.println("..........");
		return null;
	}
	
	
	@RequestMapping("/editUser")
	@Access(level=Level.USER,task="修改用户",code="user.editUser")
	public ModelAndView editUser()throws BaseException{
		System.out.println("..........");
		return null;
	}
	
	@RequestMapping("/userDetail")
	@Access(level=Level.USER,task="用户详情",code="user.userDetail")
	public ModelAndView userDetail()throws BaseException{
		System.out.println("..........");
		return null;
	}
	
	@RequestMapping("/userJson")
	@Access(level=Level.USER,task="json用户登录测试",code="user.jsonTest")
	@ResponseBody
	public Json userJson(){
		Json json=new Json();
		json.setMessage("json用户登录测试成功");
		User user=new User();
		user.setSex(User.Sex.FEMAN);
		json.setResult(user);
		return json;
	}
	
	@RequestMapping("/taskPermission")
	@Access(level=Level.PERMISSION,task="json权限测试",code="user.jsonTest")
	@ResponseBody
	public Json taskPermission(){
		Json json=new Json();
		json.setMessage("json权限测试成功");
		json.setResult("232323");
		return json;
	}

}
